<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <script src="../js/axios-0.18.0.js"></script>
    <style type="text/css">
    .el-main{
        position: absolute;
        top: 70px;
        bottom: 0px;
        left: 200px;
        right: 10px;
        padding: 0;
    }
    </style>
</head>
<body class="hold-transition skin-purple sidebar-mini">
    <div id="app">
        <el-container>
            <el-header  class="main-header" style="height:70px;">
                <nav class="navbar navbar-static-top" :class=''>
                    <!-- Logo -->
                    <a href="#" class="logo" style="text-align:center;">
                        <span class="logo-lg"><img src="../img/logo.png"></span>
                    </a>
                    <div class="right-menu">

                        <template>
                            <el-select v-model="value" placeholder="请选择角色" @change="onRole()">
                                <el-option
                                        v-for="item in options"
                                        :key="item.value"
                                        :label="item.label"
                                        :disabled="item.disabled"
                                        :value="item.value">
                                </el-option>
                            </el-select>
                        </template>

                        <span class="help"><i class="fa fa-exclamation-circle" aria-hidden="true"></i>帮助</span>
                        <el-dropdown class="avatar-container right-menu-item" trigger="click">
                            <div class="avatar-wrapper">
                                <img :src="'http://q1cxggodb.bkt.clouddn.com/'+imgdata.img" class="user-avatar" style="width: 34px;height: 34px">
                                {{username}}
                            </div>
                            <el-dropdown-menu slot="dropdown">
                                <el-dropdown-item divided>
                                    <span style="display:block;" @click="updatePortrait()">修改头像</span>
                                </el-dropdown-item>
                                <el-dropdown-item divided>
                                    <span style="display:block;" @click="update()">修改密码</span>
                                </el-dropdown-item>
                                <el-dropdown-item divided>
                                    <a href="/logout"><span style="display:block;">退出</span></a>
                                    </el-dropdown-item>
                            </el-dropdown-menu>
                        </el-dropdown>
                    </div>
                </nav>
            </el-header>
            <el-container>
                <el-aside width="200px">
                    <el-menu>
                        <el-submenu v-for="menu in menuList" :index="menu.path">
                            <template slot="title">
                                <i class="fa" :class="menu.icon"></i>
                                {{menu.name}}
                            </template>
                            <template v-for="child in menu.children">
                                <el-menu-item :index="child.path">
                                    <a :href="child.linkUrl" target="right">{{child.name}}</a>
                                </el-menu-item>
                            </template>
                        </el-submenu>
                    </el-menu>
                </el-aside>
                <el-container>
                    <iframe name="right" class="el-main" src="ordersetting.html" width="100%" height="580px" frameborder="0"></iframe>
                </el-container>
            </el-container>
        </el-container>
    </div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script>
    new Vue({
        el: '#app',
        data:{
            username:null,
            menuList:[],
            imgdata:{},
            options: [],
            value: ''
        },
        created(){
            axios.get("/user/getusername").then((res)=>{
                if(res.data.flag){
                    this.username = res.data.data;
                }
            });

            axios.post("/user/getmenu").then((res)=>{
                if(res.data.flag){
                        this.menuList = res.data.data;
                        this.$message({
                            type:'success',
                            message:res.data.message
                        })
                }else {
                    this.$message.error(res.data.message);
                }
            });

            axios.post("/user/getimg").then((res)=>{
                if(res.data.flag){
                    this.imgdata = res.data.data;
                    this.$message({
                        type:'success',
                        message:res.data.message
                    })
                }else {
                    this.$message.error(res.data.message);
                }
            });

            axios.post("/user/role").then((res)=>{
                if(res.data.flag){
                    this.options = res.data.data;
                    this.$message({
                        type:'success',
                        message:res.data.message
                    })
                }else {
                    this.$message.error(res.data.message);
                }
            });

            axios.post("/user/roleName").then((res)=>{
                if(res.data.flag){
                    this.value = res.data.data;
                    this.$message({
                        type:'success',
                        message:res.data.message
                    })
                }else {
                    this.$message.error(res.data.message);
                }
            });


        },
        methods:{
            update(){
                window.location.href = "/pages/updatepassword.html?username="+this.username;
            },
            updatePortrait(){
                window.location.href = "/pages/updateheadportrait.html";
            },
            onRole(){
                this.$confirm('是否需要切换角色, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'success'
                }).then(() => {
                    axios.post("/user/setRoleId?id="+this.value).then((res)=>{
                        if(res.data.flag){
                            this.menuList = res.data.data;
                            this.$message({
                                type:'success',
                                message:res.data.message
                            })
                        }else {
                            this.$message.error(res.data.message);
                        }
                    })
                }).catch(() => {
                    this.value = '';
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            }
        },
    });
    $(function() {
            var wd = 200;
            $(".el-main").css('width', $('body').width() - wd + 'px');
    });
</script>
</html>
